<?php

@session_start();

class C5Request
{

    static function get_parameters($names = array(), $filter_empty_value = true)
    {
        $matrix = $_REQUEST;
        if (!isset($matrix) || !is_array($matrix)) {
            if ($_SERVER["REQUEST_METHOD"] == "POST") {
                $matrix = $_POST;
            } else if ($_SERVER["REQUEST_METHOD"] == "GET") {
                $matrix = $_GET;
            }
        }
        if (empty($names)) {
            $names = array_keys($matrix);
        } else if (!is_array($names)) {
            $names = explode(",", $names);
        }

        $result = array();
        for ($i = 0; $i < count($names); $i++) {
            $name = $names[$i];
            if (array_key_exists($name, $matrix)) {
                if ($filter_empty_value == true && $matrix[$name] == "") {
                    continue;
                }
                $result[$name] = $matrix[$name];
            }
        }
        return $result;
    }

    static function get_parameter($argName, $default = "")
    {
        $matrix = self::get_parameters();
        if (array_key_exists($argName, $matrix)) {
            return $matrix[$argName];
        }
        return $default;
    }

    static function get($argName, $defaultValue = "", $replaceQuota = false)
    {
        $temp = self::get_parameter($argName, $defaultValue);
        if ($replaceQuota) {
            $temp = str_replace("'", "''", $temp);
        }
        return $temp;
    }

    static function get_int($argName, $defaultValue = -1)
    {
        $value = self::get($argName, false, $defaultValue);
        if (is_array($value)) {
            return $defaultValue;
        }
        return is_int($value * 1) ? $value : $defaultValue;
    }

}